package com.yunhe.inspect.controller;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.inspect.domain.DataInspectPlan;
import com.yunhe.inspect.model.*;
import com.yunhe.inspect.service.DataInspectPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.yunhe.common.model.ResultObject;

import java.util.List;

/**
 * @description 巡检计划表
 * @author misty
 * @date 2021-11-09
 */
@Api(value = "DataInspectPlan", description = "巡检计划", tags = {"巡检计划"})
@RestController
@RequestMapping(value = "/dataInspectPlan")
public class DataInspectPlanController {

    @Autowired
    private DataInspectPlanService dataInspectPlanService;

    /**
     * 新增
     * @author misty
     * @date 2021/11/09
     **/
    @ApiOperation("新增巡检计划表")
    @PostMapping("/createDataInspectPlan")
    public ResponseEntity<ResultObject> createDataInspectPlan(@RequestBody DataInspectPlanBo dataInspectPlanBo) throws ArgumentErrorException, InterruptedException {
        dataInspectPlanService.createDataInspectPlan(dataInspectPlanBo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 刪除
     * @author misty
     * @date 2021/11/09
     **/
    @ApiOperation("批量删除")
    @DeleteMapping("/deleteDataInspectPlan")
    public ResponseEntity<ResultObject> deleteDataInspectPlan(@RequestBody List<Integer> ids) throws ArgumentErrorException {
        dataInspectPlanService.deleteDataInspectPlan(ids);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("禁用/恢复")
    @PostMapping("/disableRecoveryDataInspectPlan")
    public ResponseEntity<ResultObject> disableRecoveryDataInspectPlan(@RequestBody DisableRecoveryStatus disableRecoveryStatus) throws ArgumentErrorException {
        dataInspectPlanService.disableRecoveryDataInspectPlan(disableRecoveryStatus);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    /**
     * 更新
     * @author misty
     * @date 2021/11/09
     **/
    @ApiOperation("更新巡检计划表")
    @PostMapping("/updateDataInspectPlan")
    public ResponseEntity<ResultObject> updateDataInspectPlan(@RequestBody DataInspectPlanBo dataInspectPlanBo) throws ArgumentErrorException {
        dataInspectPlanService.updateDataInspectPlan(dataInspectPlanBo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("查询巡检计划列表")
    @PostMapping("/findDataInspectPlan")
    public ResponseEntity<ResultObject<List<DataInspectPlanVo>>> findDataInspectPlan(@RequestBody DataInspectPlanQueryCondition dataInspectPlanQueryCondition) throws ArgumentErrorException {
        PageResult pageResult = dataInspectPlanService.findDataInspectPlan(dataInspectPlanQueryCondition);
        return new ResponseEntity(new ResultObject<>(pageResult), HttpStatus.OK);
    }

    /**
     * 查询 根据主键 id 查询
     * @author misty
     * @date 2021/11/09
     **/
    @ApiOperation("根据id查询巡检计划表")
    @GetMapping("/findDataInspectPlanById")
    public ResponseEntity<ResultObject<DataInspectPlanDetailVo>> findDataInspectPlanById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataInspectPlanService.findDataInspectPlanById(id)),HttpStatus.OK);
    }

}